package com.humble.vichatbackend.controller;

import com.humble.vichatbackend.service.ChatService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import com.humble.vichatbackend.common.BaseResponse;
import com.humble.vichatbackend.model.enums.ErrorCode;
import com.humble.vichatbackend.common.SearchRequest;
import com.humble.vichatbackend.exception.BusinessException;
import com.humble.vichatbackend.model.elastic.domain.SearchBean;
import com.humble.vichatbackend.service.SearchService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 聚合搜索接口
 */
@Controller
public class SearchController {
    @Resource
    private SearchService searchService;


    @GetMapping("/search")
    public BaseResponse<Page<SearchBean>> globalSearch(@RequestBody SearchRequest searchRequest) {
        if(searchRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return BaseResponse.success(searchService.searchGather(searchRequest));
    }

}
